<?php if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class Special_read_model extends CI_Model {
	public function __construct() {
		parent::__construct();
	}

public function get_status($num,$name,$from){
		$this->db->query("DROP TABLE IF EXISTS spread");
		$this->db->query("CREATE TEMPORARY TABLE spread AS (SELECT CONCAT(umr.`bill_year`,'-',umr.`bill_month`) bill_date, 
       umr.`sp_reason`,
       umr.`sp_remarks`,
       CONCAT(au.`first_name`,' ',au.`last_name`) reader,
       aa.`acct_name` account_name,
       aa.`acct_num` account_number,
       ad.`serial_number` meter_number
FROM ubs_meter_readings umr 
  JOIN app_users au ON au.`user_id` = umr.`print_by`
  JOIN ar_account aa ON aa.`account_id` = umr.`account_id`
  JOIN ar_device ad ON ad.`account_id` = aa.`account_id` AND ad.`status` = 'ACTV'
  WHERE umr.`sp_flag` = 'Y')");

	 	    $sql = "";
        $sql1 = ""; 
        $sql2 = "";
        $sql3 = "";
        $arr = array();
        if(!empty($num)){
          $sql1 = " reader LIKE '". $num ."' ";
          array_push($arr,$sql1);
        }
        if(!empty($name)){
          $sql2 = " bill_date = '". $name.'-'. $from ."' ";
          array_push($arr,$sql2);
        }

        $where = "WHERE ".implode(' AND ',$arr);

        $sql = "SELECT * FROM spread ".$where;

        $q = $this->db->query($sql);
        return $q->result();
}


}